package com.ruoyi.party.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.party.system.domain.MemberTarget;
import com.ruoyi.party.system.service.IMemberService;
import com.ruoyi.party.system.service.IMemberTargetService;
import com.ruoyi.party.system.service.IOrgService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发展对象信息登记Controller
 * 
 * @author 黄宝康
 * @date 2021-04-20
 */
@Controller
@RequestMapping("/business/target")
public class MemberTargetController extends BaseController
{
    private String prefix = "business/target";

    @Autowired
    private IMemberTargetService memberTargetService;
    @Autowired
    private IMemberService memberService;
    @Autowired
    private IOrgService orgService;

    @RequiresPermissions("business:target:view")
    @GetMapping()
    public String target(ModelMap mmap)
    {
    	mmap.put("orgZbs",orgService.selectOrgZbList());
    	mmap.put("members",memberService.selectMemberList(null));
        return prefix + "/target";
    }

    /**
     * 查询发展对象信息登记列表
     */
    @RequiresPermissions("business:target:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MemberTarget memberTarget)
    {
        startPage();
        List<MemberTarget> list = memberTargetService.selectMemberTargetList(memberTarget);
        return getDataTable(list);
    }

    /**
     * 导出发展对象信息登记列表
     */
    @RequiresPermissions("business:target:export")
    @Log(title = "发展对象信息登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberTarget memberTarget)
    {
        List<MemberTarget> list = memberTargetService.selectMemberTargetList(memberTarget);
        ExcelUtil<MemberTarget> util = new ExcelUtil<MemberTarget>(MemberTarget.class);
        return util.exportExcel(list, "发展对象信息登记数据");
    }

    /**
     * 新增发展对象信息登记
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
    	mmap.put("orgZbs",orgService.selectOrgZbList());
    	mmap.put("members",memberService.selectMemberList(null));
        return prefix + "/add";
    }

    /**
     * 新增保存发展对象信息登记
     */
    @RequiresPermissions("business:target:add")
    @Log(title = "发展对象信息登记", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated MemberTarget memberTarget)
    {
        return toAjax(memberTargetService.insertMemberTarget(memberTarget));
    }

    /**
     * 修改发展对象信息登记
     */
    @GetMapping("/edit/{targetId}")
    public String edit(@PathVariable("targetId") String targetId, ModelMap mmap)
    {
        MemberTarget memberTarget = memberTargetService.selectMemberTargetById(targetId);
        mmap.put("memberTarget", memberTarget);
        mmap.put("orgZbs",orgService.selectOrgZbList());
        mmap.put("members",memberService.selectMemberList(null));
        return prefix + "/edit";
    }

    /**
     * 修改保存发展对象信息登记
     */
    @RequiresPermissions("business:target:edit")
    @Log(title = "发展对象信息登记", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated MemberTarget memberTarget)
    {
        return toAjax(memberTargetService.updateMemberTarget(memberTarget));
    }

    /**
     * 删除发展对象信息登记
     */
    @RequiresPermissions("business:target:remove")
    @Log(title = "发展对象信息登记", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(memberTargetService.deleteMemberTargetByIds(ids));
    }
}
